<template>
  <div class="entity-content" :style="bodyStyle">
    <div class="entity-left" :style="bodyStyle">
      <div class="entity-left-title" :style="bodyStyle">
        数据统计
      </div>
      <div class="entity-left-ul">
        <div v-if="dataList" class="entity-left-li">
          <server-count
            v-for="(item, index) in dataList"
            :key="'index-' + index"
            :params="item"
          />
        </div>
      </div>
    </div>
    <div class="entity-right" :style="bodyStyle">
      <div class="entity-right-title" style="display: flex" :style="bodyStyle">
        <div class="custom-rate">
          <!--          <div class="right-span"></div>-->
          <div
            class="custom-rate-title"
            style="font-size: 16px;color: #303133;"
            :style="bodyStyle"
          >
            {{ entity.name }}
          </div>
          <div class="custom-rate-li">
            <el-rate
              v-model="rate"
              disabled
              style="margin-top: 7px"
              show-score
              :colors="['#ffffff', '#F7BA2A', '#FF9900']"
              text-color="#ff9900"
              score-template="{value}"
            />
          </div>
        </div>
        <div v-if="isGuest === false" class="right-span-button">
          <el-button-group size="small">
            <el-button
              v-if="entity.sfsc"
              size="small"
              type="primary"
              :loading="loadings"
              @click="qxsc(entity)"
            ><i class="el-icon-share" />&nbsp;&nbsp;取消收藏</el-button>
            <el-button
              v-else
              type="primary"
              size="small"
              :loading="loadings"
              @click="scfw(entity)"
            ><i class="el-icon-share" />&nbsp;&nbsp;我要收藏</el-button>
            <el-button
              type="primary"
              size="small"
              @click="openEntityPj(entity)"
            ><i class="el-icon-star-off" />&nbsp;&nbsp;我要评价</el-button>
            <el-button
              type="primary"
              size="small"
              @click="openAi"
            ><i class="el-icon-chat-line-round" />我要咨询</el-button>
            <el-button
              type="primary"
              size="small"
              @click="openEntity"
            ><i class="el-icon-edit" />我要办理</el-button>
          </el-button-group>
          <!--          <el-button type="primary"  @click="openEntity"></el-button>-->
        </div>
      </div>
      <div class="entity-right-content">
        <el-tabs tab-position="right" style="height: 100%">
          <el-tab-pane label="基本信息">
            <div class="custom-tab-pane">
              <div class="custom-tab-ul tab-ul-small">
                <div class="custom-label" :style="bodyStyle">
                  <i class="el-icon-school" />&nbsp;主管部门
                </div>
                <div class="custom-span">{{ entity.organization.name }}</div>
              </div>
              <div class="custom-tab-ul tab-ul-small">
                <div class="custom-label" :style="bodyStyle">
                  <i class="el-icon-menu" />&nbsp;所属系统
                </div>
                <div class="custom-span">{{ entity.ssxtmc }}</div>
              </div>
              <div class="custom-tab-ul tab-ul-small">
                <div class="custom-label" :style="bodyStyle">
                  <i class="el-icon-user" />&nbsp;负责人
                </div>
                <div class="custom-span">{{ entity.fzr }}</div>
              </div>
              <div class="custom-tab-ul tab-ul-small">
                <div class="custom-label" :style="bodyStyle">
                  <i class="el-icon-set-up" />&nbsp;服务类型
                </div>
                <div class="custom-span">
                  <span
                    v-for="(item, index) in dict.service_type"
                    :key="'lx-' + index"
                  >
                    <span v-if="entity.fwlx === item.value">
                      {{ item.label }}</span>
                  </span>
                </div>
              </div>
              <div class="custom-tab-ul tab-ul-small">
                <div class="custom-label" :style="bodyStyle">
                  <i class="el-icon-connection" />&nbsp;办理方式
                </div>
                <div class="custom-span">
                  <div
                    v-for="(item, index) in dict.service_blfs"
                    :key="'fs-' + index"
                  >
                    <div v-if="entity.blfs === item.value">
                      {{ item.label }}
                    </div>
                    <!--                    <div v-if="entity.blfs === item.value" class="el-custom-tickets">{{ item.label }}</div>-->
                  </div>
                </div>
              </div>
              <div class="custom-tab-ul tab-ul-small">
                <div class="custom-label" :style="bodyStyle">
                  <i class="el-icon-data-board" />&nbsp;平台
                </div>
                <div class="custom-span">
                  <div class="el-custom-span">
                    <i
                      v-if="entity.zxpt.indexOf('pc') !== -1"
                      class="el-icon-monitor"
                      title="PC端"
                    />&nbsp;
                    <i
                      v-if="entity.zxpt.indexOf('app') !== -1"
                      class="el-icon-mobile"
                      title="移动端"
                    />
                  </div>
                </div>
              </div>
              <!--              <div v-if="isGuest === false " class="custom-tab-ul">
                <div class="custom-label"><i class="el-icon-share" />&nbsp;是否收藏</div>
                <div class="custom-span">
                  <div v-if="entity.sfsc" class="el-custom-tickets">
                    已收藏
                    &lt;!&ndash;                    <el-button type="text">已收藏</el-button>&ndash;&gt;
                  </div>
                  <div v-else class="el-custom-tickets">
                    未收藏
                    &lt;!&ndash;                    <el-button type="text">未收藏</el-button>&ndash;&gt;
                  </div>
                </div>
              </div>-->
              <!--              <div class="custom-tab-ul">
                <div class="custom-label"><i class="el-icon-star-off" />&nbsp;服务评价</div>
                <div class="custom-span">
                  <div class="custom-rate">
                    <div class="custom-rate-title">评价数：</div>
                    <div class="custom-rate-title">{{ entity.ratecount }}</div>
                    <div class="custom-rate-title">总评分：</div>
                    <div class="custom-rate-li">
                      <el-rate
                        v-model="rate"
                        style="margin-top: 10px"
                        disabled
                        show-score
                        text-color="#ff9900"
                        score-template="{value}"
                      />
                    </div>
                  </div>
                </div>
              </div>-->
              <!--              <div class="custom-tab-ul">
                <div class="custom-label"><i class="el-icon-place" />&nbsp;办理地点</div>
                <div class="custom-span">{{ entity.bldd }}</div>
              </div>-->
              <div class="custom-label-line" :style="bodyStyle">
                <i
                  class="el-icon-info"
                  style="line-height: 40px"
                />&nbsp;服务说明
              </div>
              <div class="custom-tab-content" v-html="entity.fwsm" />
              <div class="custom-label-line" :style="bodyStyle">
                <i
                  class="el-icon-warning"
                  style="line-height: 40px"
                />&nbsp;注意事项
              </div>
              <div class="custom-tab-content" v-html="entity.zysx" />
            </div>
          </el-tab-pane>
          <el-tab-pane label="附件下载">
            <div
              v-for="(item, index) in enclosureList"
              :key="'fj-' + index"
              class="tab-pane-li"
              @click="downloadEnclosure(item)"
            >
              <el-image
                v-if="
                  item.name.indexOf('doc') !== -1 ||
                    item.name.indexOf('docx') !== -1
                "
                :src="doc"
                class="line-image"
              />
              <el-image
                v-if="
                  item.name.indexOf('xls') !== -1 ||
                    item.name.indexOf('xlsx') !== -1
                "
                :src="excel"
                class="line-image"
              />
              <el-image
                v-if="
                  item.name.indexOf('png') !== -1 ||
                    item.name.indexOf('jpg') !== -1 ||
                    item.name.indexOf('jpeg') !== -1
                "
                :src="gif"
                class="line-image"
              />
              <div class="line-title">{{ item.name }}</div>
            </div>
          </el-tab-pane>
          <el-tab-pane
            v-if="isGuest === false"
            label="评价详情"
            :style="bodyStyle"
          >
            <div class="custom-pj-body">
              <div class="custom-pj-body-header" :style="borderStyle">
                <div
                  :class="active === '0' ? 'active' : ''"
                  class="pj-item"
                  @click="queryClick('0')"
                >
                  全部
                </div>
                <div
                  :class="active === 'a' ? 'active' : ''"
                  class="pj-item"
                  @click="queryClick('a')"
                >
                  好评
                </div>
                <div
                  :class="active === 'b' ? 'active' : ''"
                  class="pj-item"
                  @click="queryClick('b')"
                >
                  差评
                </div>
              </div>
              <div class="custom-pj-body-content">
                <el-scrollbar
                  v-if="evaluateList !== null && evaluateList.length > 0"
                >
                  <div
                    v-for="item in evaluateList"
                    :key="'td-' + item.id"
                    class="dialog-evaluate-li"
                  >
                    <div class="evaluate-header">
                      <div class="question">
                        <el-rate
                          :value="builderRate(item)"
                          disabled
                          show-score
                          text-color="#ff9900"
                          style="margin-top: 10px"
                          score-template="{value}"
                        />
                      </div>
                      <div class="evaluate-date" :style="bodyStyle">
                        {{ item.createTime }}
                      </div>
                      <div class="avatar" :style="bodyStyle">
                        <label>{{ item.uname }}</label>
                      </div>
                    </div>
                    <div class="question-body">
                      <div class="question-body-item" :style="bodyStyle">
                        服务态度：<i>{{ item.fwtd }}</i>
                      </div>
                      <div class="question-body-item" :style="bodyStyle">
                        办事速度：<i>{{ item.bsxl }}</i>
                      </div>
                      <div class="question-body-item" :style="bodyStyle">
                        信息完整度：<i>{{ item.xxwzd }}</i>
                      </div>
                      <div class="question-body-item" :style="bodyStyle">
                        整体满意度：<i>{{ item.ztmyd }}</i>
                      </div>
                    </div>
                  </div>
                  <div v-if="loading" class="custom-more">加载中...</div>
                  <div v-if="disabled" class="custom-more" @click="load">
                    加载更多
                  </div>
                  <div v-if="noMore" class="custom-more">没有要加载的数据</div>
                </el-scrollbar>
                <el-empty v-else :image-size="200" />
              </div>
            </div>
          </el-tab-pane>
          <el-tab-pane v-if="entity.isShowData === true" :label="entity.sjxmc">
            <server-list
              :temp="queryParameter"
              :params="queryData"
              :fwid="entity.id"
            />
          </el-tab-pane>
        </el-tabs>
      </div>
    </div>
    <evaluate-custom ref="evaluate" @call-bak="callEntity" />
    <dialog-entity ref="openConsult" />
  </div>
</template>

<script>
import {
  analysisEntity,
  analysisGuestEntity,
  analysisGuestEnclosure,
  analysisEnclosure
} from '@/api/portal/manager/analysis/index'
import ServerList from './common/index'
import ServerCount from './common/count'
import { getToken } from '@/utils/auth'
import { delCollection, saveCollection } from '@/api/index/service/entity'
import { queryEvaluate } from '@/api/index/service/entity'
import EvaluateCustom from '@/template/entityTemp/ServerEntity/common/evaluate'
import DialogEntity from '@/components/consult/dialog.vue'
export default {
  name: 'ServerEntityV3', // 服务详情页面
  components: { DialogEntity, ServerList, EvaluateCustom, ServerCount },
  dicts: ['service_type', 'service_blfs'],
  props: {
    params: {
      type: Array
    },
    temp: {
      type: Object,
      default: () => {
        return {}
      }
    }
  },
  data() {
    return {
      doc: require('@/assets/images/doc.png'),
      eps: require('@/assets/images/eps.png'),
      excel: require('@/assets/images/excel.png'),
      gif: require('@/assets/images/gif.png'),
      pdf: require('@/assets/images/pdf.png'),
      ppt: require('@/assets/images/ppt.png'),
      txt: require('@/assets/images/txt.png'),
      zip: require('@/assets/images/zip.png'),
      circleUrl:
        'https://cube.elemecdn.com/3/7c/3ea6beec64369c2642b92c6726f1epng.png',
      dataList: [],
      evaluateList: [],
      queryParameter: {},
      queryData: [],
      enclosureList: [],
      loading: false,
      loadings: false,
      disabled: false,
      isGuest: true,
      noMore: false,
      active: '0',
      totalElements: 0,
      current: 1,
      rows: 15,
      baseURL: process.env.VUE_APP_BASE_API, // api 的 base_url
      entity: {
        organization: {},
        zxpt: ''
      },
      queryParams: {
        id: null,
        type: '0'
      },
      bodyStyle: {},
      borderStyle: {}
    }
  },
  computed: {
    themes() {
      return this.$store.getters.theme
    },
    rate() {
      if (this.entity.ratesum > 0 && this.entity.ratecount > 0) {
        return parseFloat(
          (this.entity.ratesum / (this.entity.ratecount * 4)).toFixed(1)
        )
      }
      return 5.0
    }
  },
  watch: {
    temp: {
      handler(newName, oldName) {
        this.dataList = []
        this.queryParameter = Object.assign({})
        this.queryData = []
        this.enclosureList = []
        if (undefined !== newName.pzx) {
          this.setting = JSON.parse(newName.pzx)
          this.dataList = this.setting.data
        }
        this.tid = newName.id
        this.initEntity()
        this.initEnclosure()
      },
      immediate: true, // 父组件第一次传值时，执行handler，false则第一次不执行
      deep: false // formType为对象时，设置为true，此属性监听对象发生变化
    }
  },
  mounted() {
    this.$store
      .dispatch('GetThemes')
      .then(res => {
        return true
      })
      .catch(error => {
        console.log(error)
      })
  },
  methods: {
    // 打开在线咨询
    openAi() {
      this.$refs.openConsult.open()
      this.$emit('callBack', false)
    },
    load() {
      if (this.size * (this.page + 1) <= this.totalElements) {
        this.disabled = false
        this.page = this.page + 1
        this.initEvaluate()
      } else {
        this.noMore = true
        this.disabled = false
        this.loading = false
      }
    },
    queryClick(data) {
      this.active = data
      this.evaluateList = []
      this.noMore = false
      this.disabled = true
      this.loading = false
      this.initEvaluate()
    },
    callEntity() {
      this.evaluateList = []
      this.initEvaluate()
    },
    initEntity() {
      this.evaluateList = []
      this.current = 1
      this.rows = 15
      if (getToken()) {
        this.isGuest = false
      }
      const query = {}
      if (this.params !== null && this.params.length > 0) {
        this.params.forEach(item => {
          query[item.code] = item.value
        })
      }
      if (getToken()) {
        analysisEntity(query).then(res => {
          const { data } = res
          this.entity = data
          if (
            undefined !== this.entity.jxx &&
            this.entity.jxx !== null &&
            this.entity.jxx !== ''
          ) {
            this.queryParameter = JSON.parse(this.entity.jxx)
          }
          if (
            undefined !== this.entity.tjpz &&
            this.entity.tjpz !== null &&
            this.entity.tjpz !== ''
          ) {
            const pzx = JSON.parse(this.entity.tjpz)
            this.dataList = this.dataList.concat(pzx)
          }
          this.initEvaluate()
        })
      } else {
        analysisGuestEntity(query).then(res => {
          const { data } = res
          this.entity = data
          if (
            undefined !== this.entity.jxx &&
            this.entity.jxx !== null &&
            this.entity.jxx !== ''
          ) {
            this.queryParameter = JSON.parse(this.entity.jxx)
          }
          if (
            undefined !== this.entity.tjpz &&
            this.entity.tjpz !== null &&
            this.entity.tjpz !== ''
          ) {
            const pzx = JSON.parse(this.entity.tjpz)
            this.dataList = this.dataList.concat(pzx)
          }
          // this.initEvaluate()
        })
      }
    },
    initEnclosure() {
      const query = {}
      if (this.params !== null && this.params.length > 0) {
        this.params.forEach(item => {
          query[item.code] = item.value
        })
      }
      if (getToken()) {
        analysisEnclosure(query).then(res => {
          const { data } = res
          this.enclosureList = data
        })
      } else {
        analysisGuestEnclosure(query).then(res => {
          const { data } = res
          this.enclosureList = data
        })
      }
    },
    openEntity() {
      if (
        undefined !== this.entity.openUrl &&
        this.entity.openUrl !== '' &&
        this.entity.openUrl !== null
      ) {
        window.open(this.entity.openUrl, '_blank')
      }
    },
    openEntityPj(data) {
      // 服务评价
      this.$refs.evaluate.openEntity(data)
    },
    builderRate(data) {
      if (data !== null) {
        return parseFloat(
          ((data.bsxl + data.fwtd + data.xxwzd + data.ztmyd) / 4).toFixed(1)
        )
      } else {
        return 5.0
      }
    },
    initEvaluate() {
      this.loading = true
      queryEvaluate({
        serviceId: this.entity.id,
        users: 'false',
        rows: this.rows,
        current: this.current,
        type: this.active
      })
        .then(res => {
          const { data, page } = res
          this.evaluateList = this.evaluateList.concat(data)
          this.totalElements = page.totalElements
          this.loading = false
          this.disabled = true
        })
        .catch(() => {
          this.dataList = []
          this.pagerSize = 0
          this.loading = false
          this.disabled = false
        })
    },
    scfw(data) {
      // 收藏服务
      this.loadings = true
      saveCollection({ serviceId: data.id }).then(res => {
        if (res.state === 200) {
          this.entity.sfsc = true
          this.$notify({
            title: '收藏成功',
            message: '服务收藏成功！',
            type: 'success'
          })
          this.loadings = false
        } else {
          this.$notify({
            title: '收藏失败！',
            message: res.msg,
            type: 'warning'
          })
          this.loadings = false
        }
      })
    },
    qxsc(data) {
      // 取消收藏
      this.loadings = true
      delCollection({ serviceId: data.id }).then(res => {
        if (res.state === 200) {
          this.entity.sfsc = false
          this.$notify({
            title: '取消成功',
            message: '服务取消收藏成功！',
            type: 'success'
          })
          this.loadings = false
        } else {
          this.$notify({
            title: '取消失败！',
            message: res.msg,
            type: 'warning'
          })
          this.loadings = false
        }
      })
    },
    downloadEnclosure(item) {
      if (undefined !== item.fjdz && item.fjdz !== '' && item.fjdz !== null) {
        window.open(item.fjdz, '_blank')
      }
    }
  }
}
</script>

<style scoped>
.entity-content {
  width: 100%;
  min-height: 762px;
  padding: 0px 15px;
  box-sizing: border-box;
  display: flex;
  flex-flow: row nowrap;
}

.entity-left,
.entity-right {
  padding: 0px 10px;
  box-sizing: border-box;
}
.entity-left-title {
  flex: 0 1 auto;
  border-left: 5px solid #409eff;
  border-radius: 4px 0px 0px 4px;
}
.entity-right-title {
  flex: 0 1 auto;
  display: flex;
  flex-flow: row nowrap;
  border-right: 5px solid #409eff;
  border-radius: 0px 4px 4px 0px;
}
.entity-left-title,
.entity-right-title {
  height: 50px;
  line-height: 30px;
  padding: 10px;
  box-sizing: border-box;
  background-color: #ecf5ff;
  font-size: 16px;
  color: #303133;
  font-weight: bolder;
  margin-top: 10px;
  width: 100%;
}
.entity-left,
.entity-right {
  display: flex;
}
.entity-left-ul {
  flex: 1 1;
  display: flex;
  flex-flow: column nowrap;
  padding: 10px;
  box-sizing: border-box;
}
.entity-left-li {
  flex: 0 1 auto;
}
.custom-li-line span {
  width: 100%;
  height: 25px;
  line-height: 25px;
  text-align: center;
}

.el-custom-span {
  color: #409eff;
  font-size: 14px;
}
.right-span-button {
  flex: 0 1 auto;
  /* width: 289px; */
}
.entity-right-content {
  flex: 1 1 auto;
  padding: 20px 0px;
  box-sizing: border-box;
}
.custom-tab-pane {
  width: 100%;
  height: auto;
  border-top: 1px solid #ebebeb;
  border-left: 1px solid #ebebeb;
  display: flex;
  flex-flow: row wrap;
}
.custom-tab-ul,
.custom-label-line {
  height: 40px;
  line-height: 40px;
  font-size: 14px;
  display: flex;
  flex-flow: row nowrap;
}

.custom-tab-content {
  min-height: 200px;
}
.custom-tab-ul,
.custom-tab-content {
  flex: 0 1 auto;
  width: 100%;
}
.custom-tab-content {
}
.tab-ul-small {
  width: 33.333%;
}
.entity-right {
  width: 100%;
}
.custom-label {
  flex: 0 1 auto;
  width: 130px;
  color: #909399;
  text-align: left;
  background-color: #f2f6fc;
}
.custom-span {
  flex: 1 1 auto;
}
.custom-label,
.custom-span,
.custom-label-line,
.custom-tab-content {
  border-right: 1px solid #ebebeb;
  border-bottom: 1px solid #ebebeb;
  padding: 0px 10px;
  box-sizing: border-box;
}
.custom-label-line {
  flex: 0 1 auto;
  width: 100%;
  color: #909399;
  background-color: #f2f6fc;
}
.custom-rate {
  display: flex;
  flex-flow: row nowrap;
  width: 100%;
  height: 100%;
  flex: 1 1;
}
.custom-rate-title {
  width: auto;
  font-size: 13px;
  color: #909399;
  flex: 0 1 auto;
  box-sizing: border-box;
}
.custom-rate-li {
  width: 170px;
  flex: 0 1 auto;
  box-sizing: border-box;
  margin-left: 10px;
}
.line-image {
  width: 40px;
  line-height: 40px;
  flex: 0 1 auto;
  height: 40px;
  margin-top: 5px;
}
.tab-pane-li {
  width: 100%;
  height: 50px;
  line-height: 50px;
  display: flex;
  flex-flow: row nowrap;
  cursor: pointer;
}
.line-title {
  flex: 1 1 auto;
  font-size: 16px;
  color: #409eff;
}
.custom-pj-body {
  width: 100%;
  height: 450px;
  overflow: hidden;
  padding: 10px;
  box-sizing: border-box;
}
.dialog-evaluate-li {
  width: 100%;
  line-height: 40px;
  border-bottom: 1px solid #ebebeb;
  padding: 10px 0px;
  box-sizing: border-box;
}

.evaluate-header {
  width: 100%;
  height: 40px;
  line-height: 40px;
}

.evaluate-header .block {
  float: left;
  margin-left: 10px;
}

.evaluate-header .avatar {
  width: 55px;
  height: 40px;
  line-height: 40px;
  float: right;
  margin-left: 10px;
  overflow: hidden;
  color: #999999;
  font-size: 14px;
}

.evaluate-header .question {
  float: left;
  height: 40px;
  line-height: 40px;
}
.question-body {
  width: 100%;
  height: 40px;
  line-height: 40px;
  display: flex;
  align-items: center;
}
.question-body-item {
  width: 25%;
  color: #999999;
  font-size: 14px;
}
.question-body-item i {
  font-weight: bolder;
  font-size: 14px;
}
.evaluate-date {
  float: right;
  line-height: 40px;
  font-size: 14px;
  color: #999999;
}
.custom-more {
  width: 100%;
  height: 20px;
  text-align: center;
  font-size: 12px;
  line-height: 20px;
}
.custom-pj-body-header {
  height: 50px;
  width: 100%;
  background-color: #f5f5f5;
  border-radius: 2px;
  line-height: 50px;
  padding: 0px 20px;
  box-sizing: border-box;
  display: flex;
  align-items: center;
}
.custom-pj-body-content {
  width: 100%;
  height: 400px;
  overflow: hidden;
}
.pj-item {
  width: 60px;
  cursor: pointer;
}
.pj-item.active {
  color: #00a0e9;
}
@media screen and (min-width: 1200px) {
  .entity-left {
    flex: 0 1 auto;
    width: 380px;
    flex-flow: column nowrap;
  }
  .entity-right {
    flex: 1 1 auto;
    flex-flow: column nowrap;
  }
  .entity-left-ul {
    display: flex;
    flex-flow: column nowrap;
  }
  .entity-right-content {
    flex: 1 1 auto;
  }
}

@media screen and (min-width: 815px) and (max-width: 1200px) {
}

@media screen and (max-width: 815px) {
}
</style>
